<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #container{
            width: 800px;
            border: 1px solid #333;
            /* 方式2 */
            height: 100px;
        }
        .d1,.d2,.d3,.d4{
            width: 100px;
            height: 100px;

            /* 浮动 */
            float: left;
        }
        .d1{
            background: red;
        }
        .d2{
            background: blue;
        }
        .d3{
            background: green;
        }
        .d4{
            background: pink;
        }
        .clr{
            width: 0;
            height: 0;
            clear: both;
        }
    </style>
</head>
<body>
    <div id="container">
        <div class="d1">div1</div>
        <div class="d2">div2</div>
        <div class="d3">div3</div>
        <div class="d4">div4</div>
        <!-- 方式1 -->
        <!-- <div class="clr"></div> -->
    </div>
</body>
</html>